package com.kc.gb.base.dto;


import lombok.Data;

/**
 * Created by evan on 2017/1/9.
 */
@Data
public class Result<T> {

    private static String SUCCESS_CODE = "200";
    private static String ERROR_CODE = "500";

    /**
	 * 
	 */
	private static final long serialVersionUID = 1L;


	/**
     * 成功标识
     */
    private boolean success;


    /**
     * 错误信息
     */
    private String message;

    /**
     * 错误码
     */
    private String code;


    /**
     * 返回对象
     */
    private T data;

    /**
     * 提示类型，，此处主要是用于前端统一处理提示标识
     */
    private String reminder;

    /**
     * 错误级别，，
     */
    private int errorLevel;


    public Result(){}


    public Result(String code, String message){
        this.message = message;
        this.code = code;
        if(SUCCESS_CODE.equals(code)){
            this.success = true;
        }
    };

    public Result(boolean success, String message, String code){
        this.message = message;
        this.code = code;
        this.success = success;
    };

    public Result(String message, String code, T data){
        this(code,message);
        this.data = data;
    };

    public Result(boolean success, String message, String code, T data){
        this(success,message,code);
        this.data = data;
    };

    public Result(boolean success, String message){
        this.message = message;
        this.code = code;
        this.success = success;
    };

    public static<T> Result<?> valueOf(boolean success, String message){
        String code = success ? SUCCESS_CODE : ERROR_CODE;
        return new Result(true,message,code,null);
    }

    public static Result<?> success(){
        return new Result(SUCCESS_CODE,"");
    }

    public static<T> Result<T> success(T data){
        return new Result<T>(true,null,SUCCESS_CODE,data);
    }

    public static Result<?> fail(){
        return new Result(ERROR_CODE,"");
    }

    public static Result<?> fail(String message) {
        return new Result(ERROR_CODE,message);
    }

    public static Result<?> fail(String code,String message) {
        return new Result(code,message);
    }
}
